package com.example.spinning.service;

import com.example.spinning.bean.WareHousePack;
import com.example.spinning.mapper.WareHousePackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WareHousePackService {

    @Autowired
    private WareHousePackMapper wareHousePackMapper;

    //得到打包信息
    //带有分页功能的展现数据
    public List<WareHousePack> getAllWareHousePack(Integer page, Integer count) {
        int start = (page - 1) * count;
        return wareHousePackMapper.getWareHousePack(start,count);
    }

    //找到行数
    public int getWareHousePackCount() {
        return wareHousePackMapper.getCountWareHousePack();
    }

    //根据条件找到行数
        public int getWareHousePackCountByCondition(String workshop, String customer, String date, String batch_no, String name){
        return wareHousePackMapper.getCountWareHousePackByCondition(workshop,customer,date,batch_no,name);
    }

    //根据id查询打包信息
    public WareHousePack getWareHousePackById(long id){
        WareHousePack order = wareHousePackMapper.getWareHousePackById(id);
        return order;
    }

    //根据条件模糊查询
    public List<WareHousePack> getWareHousePackByCondition(Integer page, Integer count, String workshop, String customer, String date, String batch_no, String name){
        int start = (page - 1) * count;
        return wareHousePackMapper.getWareHousePackByCondition(start,count,workshop,customer,date,batch_no,name);
    }

    //添加打包信息
    public int addWareHousePack(WareHousePack order){
        return wareHousePackMapper.addWareHousePack(order);
    }


    //修改
    public int updateWareHousePack(WareHousePack order){
        return wareHousePackMapper.updateWareHousePackById(order);
    }

    //删除
    public boolean deleteWareHousePackByIds(String ids){
        String[] split = ids.split(",");
        int result = wareHousePackMapper.delWareHousePackById(split);
        return result == split.length;
    }


}
